/**
 * Controls the pages
 */
var pagination = {
	
	/**
	 * CurrentPage
	 */
	currentPage: 0,
	
	/**
	 * The pages that exist
	 */
	pages: [
		{
		// login
			begin: function(){
				if(login.user != '') {
					pagination.currentPage = 1;
					pagination.pages[1].begin();
					pagination.changeNextButton();
					return;
				}
				login.getTeacherList();
			},
			leave: function(){
				login.sendName();
				pagination.changeNextButton();
			}
		},{
		// definition
			begin: function(){
				definition.getDefinition();
				soundbite.getSound();
			},
			leave: function(){
			}
		},{
		// draw an image
			begin: function(){
				drawing.setCanvas();
			},
			leave: function(){
				drawing.sendDrawing();
			}
		},{
		// give your definition
			begin: function(){
				definition.userDefinition();
			},
			leave: function(){
				definition.saveUserDefinition();
			}
		},{
		// view pictures/drawings
			begin: function(){
				images.getDrawings();
				pagination.changeExitButton();
			},
			leave: function(){
				
			}
		}
	],
	
	/**
	 * Change the style of button.
	 */
	changeNextButton: function(){
		var button = content.document.getElementById('piraat-nextButton');
		button.style.backgroundImage = "url(" + Woordenschat.url + "images/gaVerder.png)";
	},
	
	/**
	 * Change the style and function of the button.
	 */
	changeExitButton: function(){
		var button = content.document.getElementById('piraat-nextButton');
		button.style.backgroundImage = "url(" + Woordenschat.url + "images/sluiten.png)";
		button.onmouseup = Woordenschat.destroy;
	},
	
	/**
	 * Clears the panel.
	 */
	clearPanel: function(){
		var panel = content.document.getElementById('piraat-panel');
		while (panel.firstChild){
			panel.removeChild(panel.firstChild);
		}
	},
	
	/**
	 * Displaying information about where the User is being located.
	 */
	pageInfo: function() {
		var maindiv = content.document.getElementById('piraat-panel');
		if (content.document.getElementById('piraat-currentPageInfo')){
			maindiv.removeChild(content.document.getElementById('piraat-currentPageInfo'));
		}
		var div = content.document.createElement('div');
		div.id = 'piraat-currentPageInfo';
		div.appendChild(document.createTextNode('Stap ' + (pagination.currentPage+1) + ' van ' + pagination.pages.length));
		maindiv.appendChild(div);
	},

	/**
	 * Navigate to the next page, stop if the last page is reached.
	 */
	nextPage: function(){
		if(pagination.pages[pagination.currentPage].leave != undefined)
			pagination.pages[pagination.currentPage].leave();
		pagination.currentPage++;
		if(pagination.currentPage > pagination.pages.length-1 || pagination.currentPage < 0) {
			return;
		}
		pagination.clearPanel();
		pagination.pages[pagination.currentPage].begin();
		pagination.pageInfo();
	}
}